package br.com.hugo.senai.relatorio;

import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.*;
import java.util.List;

public class Conexao {

    public static Connection getConnection() throws Exception {

        Path path = Paths.get("config.txt");

        List<String> linhas = Files.readAllLines(path, StandardCharsets.UTF_8);

        String senha = "";
        String usuario = "";
        String url = "";

        for (String a : linhas) {

            String[] split = a.split(";");
            url = split[0];
            usuario = split[1];
            senha = split[2];

        }

        try {
            Class.forName("com.mysql.jdbc.Driver");
            return DriverManager.getConnection(url, usuario, senha);
        } catch (ClassNotFoundException | SQLException e) {
            return null;

        }
    }

}
